<template>
  <div class="option_item" :style="isActive ? bgColor : ''">
    <div class="icon_wrapper" :style="iconColor">
      <span class="iconfont icon" :class="icon"></span>
    </div>
    <div class="title">
      <span>{{ title }}</span>
      <div v-if="Number(tipNum) > 0" class="num">
        <span>{{ tipNum }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  icon: {
    type: String,
    default: ''
  },
  bgc: {
    type: String,
    default: ''
  },
  path: {
    type: String,
    default: ''
  },
  tipNum: {
    type: [Number, String],
    default: 0
  },
  isActive: {
    type: Boolean,
    default: false
  }
})

// 计算图标的颜色
const iconColor = computed(() => {
  return `background-color: ${props.bgc};`
})

// 计算背景色
const bgColor = computed(() => {
  return props.isActive ? 'background-color: #c8c7c6;' : ''
})
</script>

<style lang="scss" scoped>
.option_item {
  height: 50px;
  padding: 10px;
  display: flex;
  box-sizing: border-box;
  align-items: center;

  &:hover {
    background-color: #c8c7c6;
  }

  .icon_wrapper {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;

    .icon {
      font-size: 20px;
      color: #fff;
    }
  }

  .title {
    flex: 1;
    margin-left: 10px;
    font-size: 14px;
    color: #333;
    display: flex;
    justify-content: space-between;

    .num {
      width: 14px;
      height: 14px;
      color: #f5f5f5;
      font-size: 12px;
      text-align: center;
      line-height: 14px;
      padding: 2px;
      border-radius: 50%;
      background-color: red;
    }
  }
}
</style>
